package org.anlu.paypallesson02.config;

import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: anlu
 * @Date: 2021/07/19
 * @Description:
 */
@Configuration
@Slf4j
public class PayPalConfig {
    @Value("${paypal.client.app}")
    private  String clientId;
    @Value("${paypal.client.secret}")
    private  String clientSecret;
    @Value("${paypal.mode}")
    private  String mode;

    @Bean
    public PayPalHttpClient payClient() {
        log.info("mode={}, clientId={}, clientSecret={}", mode, clientId, clientSecret);
//        PayPalEnvironment environment = mode.equals("live") ? new PayPalEnvironment.Live(clientId, clientSecret) : new PayPalEnvironment.Sandbox(clientId, clientSecret);
        PayPalEnvironment environment = new PayPalEnvironment.Sandbox(clientId, clientSecret);
        return new PayPalHttpClient(environment);
    }

}
